import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { WuXingSkillItem2 } from "./WuXingSkillItem2";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { WuXingPlayerInfo } from "../../model/wuxing/WuXingPlayerInfo";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
type int = number;
//class WuXingSkillList
    
    export  class WuXingSkillList /* flash.display.Sprite */
    {
        constructor(arg1: int, arg2: int, arg3: int=75, arg4: Boolean=true)
        {
            
            this._width = arg1;
            this._height = arg2;
            this._gap = arg3;
            this._showTxt = arg4;
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            this._skillItemsBody = new Object /* flash.display.Sprite */();
            this._skillItemsBody.x = 0;
            this._skillItemsBody.y = 0;
            addChild(this._skillItemsBody);
            LoaderHelp.addResCallBack("wuxingbg.swf", this.onFrameLodedHandler);
            return;
        }

        /* internal  */onOptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._optAble) 
            {
                return;
            }
            var loc1=arg1.target as GButton;
            if (loc1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingSkillChangeReq, loc1.name));
            }
            return;
        }

        protected onFrameLodedHandler(): void
        {
            var loc3=null;
            var loc4=null;
            var loc5=null;
            this._wxSkillItems = new Map<any, any> /* flash.utils.Dictionary */();
            var loc1=1;
            var loc2=5;
            while (loc1 <= loc2) 
            {
                loc3 = GlobalClass.getInstance("wxSkill_" + loc1);
                (loc4 = new WuXingSkillItem2(loc3, loc1, this._showTxt)).optAble = this._optAble;
                this._wxSkillItems[loc1] = loc4;
                this._skillItemsBody.addChild(loc4);
                loc4.x = 6 + (loc1 - 1) * this._gap;
                loc4.y = 2;
                if (loc1 != loc2) 
                {
                    (loc5 = ResouceConst.getScaleBitmap(ImagesConst.VSpliteLine)).height = this.height;
                    loc5.y = 0;
                    loc5.x = 71 + (this._gap - 75) / 2 + (loc1 - 1) * this._gap;
                    this._skillItemsBody.addChild(loc5);
                }
                ++loc1;
            }
            this.refreshMainAttr(this._info);
            return;
        }

        public updateData(arg1: WuXingPlayerInfo, arg2: Boolean=false): void
        {
            if (!arg1) 
            {
                return;
            }
            this._info = arg1;
            this.refreshMainAttr(arg1);
            if (arg2) 
            {
                this.updateOptBtn();
            }
            else 
            {
                this.hideOptBtn();
            }
            return;
        }

        public set optAble(arg1: Boolean)
        {
            var loc1=null;
            this._optAble = arg1;
            var loc2=0;
            var loc3=this._wxSkillItems;
            for(loc1 of loc3) 
            {
                if (!loc1) 
                {
                    continue;
                }
                loc1.optAble = arg1;
            }
            return;
        }

        /* internal  */refreshMainAttr(arg1: WuXingPlayerInfo): void
        {
            var loc1=null;
            var loc2=null;
            if (!arg1 || !this._wxSkillItems) 
            {
                return;
            }
            var loc3=0;
            var loc4=this._wxSkillItems;
            for (loc1 in loc4) 
            {
                loc2 = this._wxSkillItems[loc1];
                loc2.updateData(arg1);
            }
            return;
        }

        /* internal  */updateOptBtn(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=0;
            if (!this._info) 
            {
                return;
            }
            if (!this._btnItems) 
            {
                this._btnItems = new Map<any, any> /* flash.utils.Dictionary */();
                loc3 = 1;
                loc4 = 5;
                while (loc3 <= loc4) 
                {
                    loc1 = ObjCreate.createGButton(Language.getString(26399), 0, 0, 44, 22, this);
                    loc1.x = 14 + (loc3 - 1) * this._gap;
                    loc1.y = 115;
                    loc1.name = loc3.toString();
                    this._btnItems[loc3] = loc1;
                    loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtnClickHandler);
                    ++loc3;
                }
            }
            var loc5=0;
            var loc6=this._btnItems;
            for (loc2 in loc6) 
            {
                loc1 = this._btnItems[loc2];
                if (int(loc2) == this._info.mainAttribute) 
                {
                    loc1.enabled = false;
                    continue;
                }
                loc1.enabled = true;
            }
            return;
        }

        /* internal  */hideOptBtn(): void
        {
            var loc1=null;
            if (this._btnItems) 
            {
                var loc2=0;
                var loc3=this._btnItems;
                for(loc1 of loc3) 
                {
                    if (!loc1.parent) 
                    {
                        continue;
                    }
                    loc1.parent.removeChild(loc1);
                }
            }
            return;
        }

        public /* override */ get width(): number
        {
            return this._width;
        }

        public /* override */ get height(): number
        {
            return this._height;
        }

        /* internal */ /* var */_wxSkillItems: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_skillItemsBody: Object /* flash.display.Sprite */;

        /* internal */ /* var */_btnItems: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_width: int;

        /* internal */ /* var */_height: int;

        /* internal */ /* var */_gap: int;

        /* internal */ /* var */_showTxt: Boolean;

        /* internal */ /* var */_info: WuXingPlayerInfo;

        /* internal */ /* var */_optAble: Boolean=true;
    }
